//1.导入koa-router
const Router = require('koa-router')
const {auth} = require('../middleware/auth.middleware')
const {validator,goodsIfExist} = require('../middleware/cart.middleware')
const {add,findAll,update,remove,selectAll,selectUnAll} = require('../controller/cart.controller')
//2.实例化router对象
const router = new Router({prefix:'/carts'})
//3.编写路由规则
//3.1添加到购物车接口：登录，格式
router.post('/',auth,validator({goods_id:'number'}),goodsIfExist,add)

router.get('/',auth,findAll)

//更新购物车接口
router.patch('/:id',auth,validator({
    number:{type:'number',required:false},
    selected:{type:'bool',required:false}
}),update)

//删除购物车接口
router.delete('/',auth,validator({ids:'array'}),remove)

//购物车商品全选
router.post('/selectAll',auth,validator({selecteId:'number'}),selectAll)
router.post('/selectUnAll',auth,selectUnAll)
//4.导出router对象

module.exports = router

